package com.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class AccessUtils {
	public static void main(String[] args) throws Exception {
		Connection c = getConnection();

		ResultSet rs;
		Statement stmt;
		String sql = "select id, link_name, link_url, link_target, link_params, sort_num from site_links order by sort_num";
		try {
			stmt = c.createStatement();
			rs = stmt.executeQuery(sql);
			while (rs.next()) {
				System.out.println(rs.getString("link_name"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block   
			e.printStackTrace();
		}

	}

	public static Connection getConnection() throws Exception {
		/**配置数据源后*/
		//String URL="jdbc:odbc:<MS Access Database配置数据源名称>";   
		//Connection c=DriverManager.getConnection(URL,"","");   
		/**不配置数据源*/
		//jdbc:odbc:DRIVER={Microsoft Access Driver<此处必须有空格 >(*.mdb,<注意此处必须有一空格>*.accdb)};DBQ=<数据库名称路径>[;pwd=password]   
		String url1 = "jdbc:odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=F:/test/data.accdb";
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
		Connection c = DriverManager.getConnection(url1);
		System.out.println(c);
		return c;
	}

}
